/*
 * HttpTokenAuth.h
 *
 *  Created on: 2018年2月9日
 *      Author: terry
 */

#ifndef HTTPTOKENAUTH_H_
#define HTTPTOKENAUTH_H_

#include "HttpUserStore.h"
#include <functional>
#include <vector>


struct HttpUserInfo
{
	int id;
	std::string username;
	std::string role;

	HttpUserInfo()
		:id()
	{
	}
};


class HttpTokenAuth
{
public:
	static const size_t EXPIRATION = 60 * 60;

	typedef std::function< void(const std::string& token, int uid, const std::string& username, int status) >	UserStatusListener;


public:
	virtual ~HttpTokenAuth() {}

	virtual size_t getExpiration() =0;

	virtual void setExpiration(size_t seconds) =0;

	virtual bool login(const std::string& username, const std::string& password, std::string& token) =0;

	virtual void logout(const std::string& token) =0;

	virtual bool check(const std::string& token, std::string& username) =0;

	virtual void clear() =0;

	virtual size_t size() =0;

	virtual bool getAt(size_t idx, std::string& username, std::string& token) =0;

	virtual bool putUserInfo(const std::string& token, const HttpUserInfo& info) =0;

	virtual bool getUserInfo(const std::string& token, HttpUserInfo& info) =0;

	virtual bool putToken(const std::string& token, const std::string& username, int expiration) =0;


	virtual bool touch(const std::string& token) =0;

	virtual size_t listUser(std::vector<std::string>& users) =0;

	virtual void setUserStatusListener(UserStatusListener listener) =0;

	virtual void checkExpired() =0;


};

#endif /* HTTPTOKENAUTH_H_ */
